package com.ruoyi.biz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.collect.domain.CollectCourseVideos;
import com.ruoyi.collect.service.ICourseVideosService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程视频管理Controller
 *
 * @author ruoyi
 * @date 2025-01-19
 */
@RestController("bizCourseVideosController")
@RequestMapping("/collect/course-videos")
public class CourseVideosController extends BaseController
{
    @Autowired
    private ICourseVideosService courseVideosService;

    /**
     * 查询课程视频列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(CollectCourseVideos courseVideos)
    {
        startPage();
        List<CollectCourseVideos> list = courseVideosService.selectCourseVideosList(courseVideos);
        return getDataTable(list);
    }

    /**
     * 导出课程视频列表
     */
    @PreAuthorize("@ss.hasPermi('collect:course-videos:export')")
    @Log(title = "课程视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CollectCourseVideos courseVideos)
    {
        List<CollectCourseVideos> list = courseVideosService.selectCourseVideosList(courseVideos);
        ExcelUtil<CollectCourseVideos> util = new ExcelUtil<CollectCourseVideos>(CollectCourseVideos.class);
        util.exportExcel(response, list, "课程视频数据");
    }

    /**
     * 获取课程视频详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(courseVideosService.selectCourseVideosById(id));
    }

    /**
     * 新增课程视频
     */
    @Anonymous
    @Log(title = "课程视频", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CollectCourseVideos courseVideos)
    {
        return toAjax(courseVideosService.insertCourseVideos(courseVideos));
    }

    /**
     * 修改课程视频
     */
    @Anonymous
    @Log(title = "课程视频", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CollectCourseVideos courseVideos)
    {
        return toAjax(courseVideosService.updateCourseVideos(courseVideos));
    }

    /**
     * 删除课程视频
     */
    @Anonymous
    @Log(title = "课程视频", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(courseVideosService.deleteCourseVideosByIds(ids));
    }

    /**
     * 根据课程ID查询视频列表（匿名访问）
     */
    @Anonymous
    @GetMapping("/course/{courseId}")
    public AjaxResult getVideosByCourseId(@PathVariable("courseId") Long courseId)
    {
        List<CollectCourseVideos> list = courseVideosService.selectCourseVideosByCourseId(courseId);
        return success(list);
    }

    /**
     * 批量新增课程视频
     */
    @Anonymous
    @Log(title = "批量新增课程视频", businessType = BusinessType.INSERT)
    @PostMapping("/batch")
    public AjaxResult batchAdd(@RequestBody List<CollectCourseVideos> courseVideosList)
    {
        return toAjax(courseVideosService.batchInsertCourseVideos(courseVideosList));
    }

    /**
     * 根据课程ID删除所有视频
     */
    @Anonymous
    @Log(title = "删除课程所有视频", businessType = BusinessType.DELETE)
    @DeleteMapping("/course/{courseId}")
    public AjaxResult removeByCourseId(@PathVariable("courseId") Long courseId)
    {
        return toAjax(courseVideosService.deleteCourseVideosByCourseId(courseId));
    }
}
